#include "PhantomRunnerFactory.h"

#include <exception>
#include "..\\PhantomRunner\\PhantomRunner.h"

//////////////////////////////////////////////////////////////////////////////////


PhantomRunnerFactory::PhantomRunnerFactory()
{
	m_library = ::LoadLibrary("PhantomRunner.dll");
	if (!m_library)
		throw std::exception("Dll not found");

	mf_CreatePhantomRunner 
		= (CREATEPHANTOMRUNNER) ::GetProcAddress(m_library, "CreatePhantomRunner");
	mf_DeletePhantomRunner
		= (DELETEPHATOMRUNNER) ::GetProcAddress(m_library, "DeletePhatomRunner");
}


//////////////////////////////////////////////////////////////////////////////////


PhantomRunnerFactory::~PhantomRunnerFactory()
{
	::FreeLibrary(m_library);
}


//////////////////////////////////////////////////////////////////////////////////


HRESULT PhantomRunnerFactory::CreatePhantomRunner(PhantomRunner *&_runner)
{
	return mf_CreatePhantomRunner( _runner, "gnugo.exe", "--mode gtp" );
}


//////////////////////////////////////////////////////////////////////////////////


HRESULT PhantomRunnerFactory::DeletePhantomRunner(PhantomRunner *&_runner)
{
	return mf_DeletePhantomRunner( _runner );
}


//////////////////////////////////////////////////////////////////////////////////